<template>
  <div id="app">
    <el-form class="form" ref="form" :rules="rules" :model="form">
      <!-- 活动名称 -->
      <el-form-item label="活动名称" prop="name">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <!-- 活动区域 -->
      <el-form-item label="活动区域" prop="region">
        <el-select v-model="form.region" placeholder="请选择活动区域">
          <el-option
            v-for="(item, index) in regionList"
            :key="item.id"
            :label="item.name"
            :value="item.name"
          ></el-option>
        </el-select>
      </el-form-item>
      <!-- 活动时间 -->
      <el-form-item label="活动时间" required>
        <el-form-item prop="date"
          ><el-date-picker v-model="form.date" type="date"></el-date-picker
        ></el-form-item>
        -
        <el-form-item prop="time"
          ><el-date-picker v-model="form.time" type="datetime"></el-date-picker
        ></el-form-item>
      </el-form-item>
      <!-- 及时配送 -->
      <el-form-item label="及时配送">
        <el-switch v-model="form.isCheck"></el-switch>
      </el-form-item>
      <!-- 活动性质 -->
      <el-form-item label="活动性质" prop="type">
        <el-checkbox-group v-model="form.type">
          <el-row>
            <el-col :span="8">
              <el-checkbox label="美食/餐厅线上活动" name="type"></el-checkbox>
            </el-col>
            <el-col :span="8">
              <el-checkbox label="地推活动" name="type"></el-checkbox>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-checkbox label="线下主题活动" name="type"></el-checkbox>
            </el-col>
            <el-col :span="8">
              <el-checkbox label="单纯品牌曝光" name="type"></el-checkbox>
            </el-col>
          </el-row>
        </el-checkbox-group>
      </el-form-item>
      <!-- 特殊资源 -->
      <el-form-item label="特殊资源" prop="resource">
        <el-radio-group v-model="form.resource">
          <el-radio label="线上品牌商赞助"></el-radio>
          <el-radio label="线下场地免费"></el-radio>
        </el-radio-group>
      </el-form-item>
      <!-- 活动形式 -->
      <el-form-item label="活动形式" prop="desc">
        <el-input type="textarea" v-model="form.desc"></el-input>
      </el-form-item>
      <!-- 提交 -->
      <el-form-item label="">
        <el-button type="primary" @click="onSubmit">立即创建</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getRegion } from "./api/myapi";
export default {
  name: "App",
  components: {},
  async created() {
    // 接收一个Promise
    let regionList = await getRegion();
    // console.log(regionList);
    this.regionList = regionList;
  },
  methods: {
    onSubmit: function () {
      this.$refs["form"].validate((valid) => {
        console.log("valid", valid);
      });
    },
  },
  data: function () {
    return {
      // 数据
      form: {
        name: "",
        region: "",
        date: "",
        time: "",
        isCheck: false,
        type: [],
        resource: "resource",
        desc: "",
      },
      // 下拉数据
      regionList: [],
      // 规则校验
      rules: {
        name: [{required: true,message: "请选择活动名称", trigger: "change"}],
        region: [{required: true,message: "请选择活动区域", trigger: "blur"}],
        date: [{required: true,message: "请输入日期", trigger: "blur"}],
        time: [{required: true,message: "请输入时间", trigger: "blur"}],
        type: [{required: true,message: "请选择活动类型", trigger: "blur"}],
        resource: [{required: true,message: "请选择活动资源", trigger: "blur"}],
        desc: [{required: true,message: "请选择活动性质", trigger: "blur"}],
      },
    };
  },
};
</script>

<style>
.form {
  width: 32vw;
}
</style>
